/*
*   Coder : Dzlua
*   Email : 505544956@qq.com
*   Time  : 2017/08/08
*/
#include "ClientTool.hpp"
#include "data_generate.hpp"
#include "ui/main.hpp"

#include <iomanip>

int main(int argc, char *argv[])
{
    SetConsoleOutputCP(CP_UTF8);

    if (argc == 1) {
        //ui
        return ui::main();
    }

    if (argc != 6 && argc != 7) {
        fprintf(stderr, "Usage: ServerTestTool <host_ip> <port> <threads> <sessions> <time_seconds> <library, null for random>\n");
        return -1;
    }

    const char* ip = argv[1];
    uint16_t port = static_cast<uint16_t>(atoi(argv[2]));
    int threadCount = atoi(argv[3]);
    int sessionCount = atoi(argv[4]);
    int timeout = atoi(argv[5]);
    std::string library;
    if (argc == 7) library = argv[6];

    std::string serverAddr = std::string(ip) + ":" + std::to_string(port);
    Client client(serverAddr, sessionCount, timeout, threadCount
                , [&library]() -> std::shared_ptr<DataPkg> {
            return DataGenerate::Random(library);
        });
    client.Run();

    return 0;
}